// pages/detail/detail.js
Page({
  data: {
    item: null
  },

  onLoad: function(options) {
    if (options.data) {
      const item = JSON.parse(decodeURIComponent(options.data));
      this.setData({
        item: item
      });
      
      // 设置页面标题
      wx.setNavigationBarTitle({
        title: item.name
      });
    }
  },

  previewImage: function() {
    wx.previewImage({
      urls: [
        '/images/laptop1.jpg'
      ]
    });
  },

  contactUser: function() {
    const phone = this.data.item.contactInfo;
    
    wx.showActionSheet({
      itemList: ['拨打电话', '复制号码'],
      success: (res) => {
        if (res.tapIndex === 0) {
          wx.makePhoneCall({
            phoneNumber: phone
          });
        } else if (res.tapIndex === 1) {
          wx.setClipboardData({
            data: phone,
            success: () => {
              wx.showToast({
                title: '号码已复制',
                icon: 'success'
              });
            }
          });
        }
      }
    });
  },

  onShareAppMessage: function() {
    return {
      title: `寻物启事：${this.data.item.name}`,
      path: `/pages/detail/detail?data=${encodeURIComponent(JSON.stringify(this.data.item))}`
    };
  }
});